package fu.abc.controller;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import fu.abc.DAO.LocationDAO;

/**
 * Servlet implementation class SendMail
 */
@WebServlet("/SendMail")
public class SendMail extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public SendMail() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

		int encode = Integer.parseInt(request.getParameter("encode"));
		String email = request.getParameter("email");
		
		String mailport = "587";
		String from = "sinhndse02395@fpt.edu.vn";
		String fromPass = "ducsinh";
		String fromhost = "smtp.gmail.com";
		String to = email;
		String subject = "Link chỉnh sửa địa điểm của Vnplace";
		String msg ="localhost:8080/Vnplace/end-user/editlocation.jsp?encode="+encode+"";
		
		LocationDAO localdao = new LocationDAO();
		localdao.sendEmail(mailport, from, fromPass, fromhost, to, subject, msg);
		
	}

}
